<?php

namespace App\Service;

use Hyperf\Redis\Redis;
use Hyperf\Di\Annotation\Inject;


/**
 * Socket客户端ID服务
 *
 * @package App\Service
 */
class SocketClientService
{


    /**
     * @Inject()
     * @var Redis
     */
    private $redis;


    public function bindGame($client_id, $activityId)
    {

        $r = $this->redis->sAdd(config('cache.prefix')."SCREEN_SOCKET_$activityId", $client_id);
        $this->redis->hSet(config('cache.prefix')."SCREEN_SOCKET", (string)$client_id, (string)$activityId);
    }


    public function getFdByGame($activityId)
    {
        info('getfd', [$activityId]);

        $r = $this->redis->sMembers(config('cache.prefix')."SCREEN_SOCKET_$activityId");

        info('r', [$r]);
        return $r;
    }


    public function bindScreenId($activityId, $screenId)
    {

        $r = $this->redis->set(config('cache.prefix')."SCREEN_ACTIVITY_$activityId", $screenId);
//        $this->redis->hSet(config('cache.prefix')."SCREEN_SOCKET", (string)$client_id, (string)$activityId);
    }

    // 绑定选手大屏
    public function bindScreen($client_id, $screenId)
    {
        $r = $this->redis->sAdd(config('cache.prefix')."SCREEN_ID_SOCKET_$screenId", $client_id);
        $this->redis->hSet(config('cache.prefix')."SCREEN_ID_SOCKET", (string)$client_id, (string)$screenId);
    }
}
